<html>
	<head>
		
		<?php
        INCLUDE 'header.php';
		if(isset($_POST["nome"]))
		{
		$nome = $_POST["nome"];
		$raca = $_POST["raca"];
	
        $sql = "INSERT INTO animal(nome, raca) 
		values('$nome','$raca')";
		pg_query($sql);
		//echo $sql;
		
		$mensagem = "Dados cadastrados com sucesso!";
	    echo "<p style=\"color:green; margin-top:20px; margin-left:10px;\">".$mensagem."</p>";
	    }
		//recebe dados par alteração
		 if(isset($_GET["id"]) == false)
		{
			header("listarAnimais.php");
		}
		$id = $_GET["id"];
		$sql = "select * from animal where id=$id";
		$resultado = pg_query($sql);
		$linha = pg_fetch_assoc($resultado);
		
        ?>
		
		<title>Sistema de controle de fazendas</title>
	</head>
	<body>
		<feeldset>
			
	 <form action="cadastroAnimal.php" method="post">
	<div class="pull-right"> 
		<div class="btn" title="novo animal"><i class="icon-edit"></i><a></a></div>
		<div class="btn" title="sair"><i class="icon-share-alt"></i><a></a></div>
		</div>
        
			<legend><i class="icon-edit"></i>Cadastro de animal</legend>
	
		<div class="controls controls-row">
		<div class="control-group span">
		
			<label>id</label>
			<input type="text" class="input-large" redyonly name="id" value="<?php echo $linha["id"]?> "/>
			
			
			
		</div>
		</div>
		<div class="controls controls-row">
		<div class="control-group span">
			<label>Nome</label>
			<input type="text" class="input-large" name="nome" value="<?php echo $linha["nome"]?> "></input>
			<label>Raça</label>
			<input type="text" class="input-large" name="raca" value="<?php echo $linha["raca"]?> "></input>
		</div>
		</div>
			
		
		<div class="form-actions">
		<div class="pull-right">
			<button class="btn btn-warning"><i class="icon-ok icon-white"></i> salvar</button>
			<button class="btn btn-warning"><i class="icon-trash icon-white"></i> limpar campos</button>
		</div>
		</div>
		</form>
		</feeldset>
	</body>
</html>